<template>
	<view class="container">
		<view class="coach">
			<uni-forms ref="form" :model="coach" labelWidth="80px">
				<uni-forms-item label="教练姓名" name="coachName">
					<uni-easyinput v-model="coach.coachName" placeholder="请输入教练姓名" />
				</uni-forms-item>
				<uni-forms-item label="底薪" name="salaryBasic">
					<uni-easyinput v-model="coach.salaryBasic" placeholder="请输入底薪" type="digit" />
				</uni-forms-item>
				<uni-forms-item label="课时费" name="classFee">
					<uni-easyinput v-model="coach.classFee" placeholder="请输入课时费" type="digit" />
				</uni-forms-item>
				<uni-forms-item label="备注" name="remark">
					<uni-easyinput v-model="coach.remark" placeholder="请输入备注" />
				</uni-forms-item>
			</uni-forms>
			<button type="primary" @click="submit"
				style="color:#ffffff;backgroundColor:#993399;borderColor:#993399;">提交</button>
		</view>
	</view>
</template>

<script>
  import { updateCoach } from "@/api/puyu/coach";
	export default {
		data() {
			return {
				coach: {
					coachId: "",
					coachName: "",
					salaryBasic: "",
					classFee: "",
					remark: ""
				},
				rules: {
					coachName: {
						rules: [{
							required: true,
							errorMessage: '教练不能为空'
						}]
					},
				}
			}
		},
		computed: {
		},

		created() {
		},
		onLoad(option) {
		  const item = JSON.parse(decodeURIComponent(option.item));
		  this.coach = item;
		},

		onReady() {
			this.$refs.form.setRules(this.rules)
		},
		methods: {
			submit(ref) {
				this.loading = true;
				this.$refs.form.validate().then(res => {
					updateCoach(this.coach).then(response => {
						this.$modal.msgSuccess("修改成功!")
						this.loading = false;
						this.$tab.navigateBack();
					})
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #ffffff;
	}

	.coach {
		padding: 15px;
		background-color: #fff;
	}

	.segmented-control {
		margin-bottom: 15px;
	}

	.button-group {
		margin-top: 15px;
		display: flex;
		justify-content: space-around;
	}

	.form-item {
		display: flex;
		align-items: center;
		flex: 1;
	}

	.button {
		display: flex;
		align-items: center;
		height: 35px;
		line-height: 35px;
		margin-left: 10px;
	}
</style>